-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve the performance of the FusionCacheProvider #249
Conversation
An `InvalidOperationException` is always better than a `NullReferenceException`, even in unit tests.
No matter how it's retrieved, either through IFusionCacheProvider or directly by requesting the IFusionCache.
By storing the caches in a dictionary so that retrieving the cache can be performed in O(1) instead of O(n).
Hi @0xced I updated this branch based on the new main, and pushed some changes which build upon your work and can make it even better. Basically instead of storing an IEnumerable to iterate on at every Finally I've made the tests a little better around these scenarios. Thoughts? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the latest changes it LGTM: if you agree I can proceed and merge this.
Looks good to me too! |
Storing the caches in a dictionary upfront allows to retrieve the cache in O(1) instead of O(n).
Using
Lazy<IFusionCache>
allows to preserve the semantic of throwing when accessing the (incorrectly configured) caches.Also, the
DependencyInjectionTests
were very slightly improved:GetRequiredService
instead ofGetService
plus the null-forgiving operator because anInvalidOperationException
is always better than aNullReferenceException
, even in unit tests.IFusionCache
instance is always the same no matter how it's retrieved, either throughIFusionCacheProvider
or directly by requesting theIFusionCache
.